package com.xj.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * Profile:
 *      Spring为我们提供的可以根据当前环境，动态的激活和切换一系列组件的功能；
 * 开发环境、测试环境、生产环境
 * 数据源（/A,/B./C)
 * @author xujiang
 * @date 2021/1/28 22:49
 */
@Configuration
public class MainConfigOfProfile {

    @Bean
    public DataSource dataSourcePro() throws PropertyVetoException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setUser("root");
        dataSource.setPassword("query");
        dataSource.setJdbcUrl("jdbc:mysql://139.224.233.35:3306/mybatis");
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        return dataSource;
    }
    @Bean
    public DataSource dataSourceTest() throws PropertyVetoException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setUser("root");
        dataSource.setPassword("query");
        dataSource.setJdbcUrl("jdbc:mysql://139.224.233.35:3306/mybatis");
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        return dataSource;
    }
    @Bean
    public DataSource dataSourceDev() throws PropertyVetoException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setUser("root");
        dataSource.setPassword("query");
        dataSource.setJdbcUrl("jdbc:mysql://139.224.233.35:3306/mybatis");
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        return dataSource;
    }
}
